﻿using Common.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;


namespace Wicresoft.EKA.ITSM.Web.WebPortal.Extensions
{
    public class AccountExceptionFilter : System.Web.Mvc.FilterAttribute, System.Web.Mvc.IExceptionFilter
    {

        private static readonly ILog logger = LogManager.GetCurrentClassLogger();

        //当然是发生异常时被调用了   
        /// <summary>
        /// "Error (9093): User is currently connected from another machine"
        /// </summary>
        /// <param name="filterContext"></param>
        public void OnException(ExceptionContext filterContext)
        {
            try
            {
                if (filterContext.Exception is BMC.ARSystem.ARException &&
                    filterContext.Exception.Message.Contains("9093"))
                {
                    HttpContext.Current.Response.Redirect("~/Info/AcountError.html");
                    filterContext.ExceptionHandled = true;//异常已经处理，不要再次处理了   
                }

                if (filterContext.Exception.Message.StartsWith("The ARLoginContext pool don't have the Key"))
                {
                    HttpContext.Current.Response.Redirect("~/Account/Login");
                    filterContext.ExceptionHandled = true;//异常已经处理，不要再次处理了   
                }

                if (filterContext.Exception is BMC.ARSystem.ARException)
                {
                    HttpContext.Current.Response.Redirect("~/Account/Login");
                    filterContext.ExceptionHandled = true;//异常已经处理，不要再次处理了   
                }
            }
            catch (Exception e)
            {
                logger.Error(e);
            }
        }
    }

}